<!--
 	* @author hemengxia
 	积分兑换配置---兑换记录--兑换明细
-->
<template>
  <section class="integral-exchange-record-detail">
    <!--<el-collapse-transition>
      <section v-show="searchshow" class="main-search separate">
        <section class="search-inner">
          <el-row>

            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">是否中奖</div>
                <el-select v-model="search.isDraw" placeholder="请选择是否中奖搜索" style="width: 80%;">
                  <el-option
                      v-for="item in isDrawOptions"
                      :key="item.id"
                      :label="item.dictName"
                      :value="item.id"
                  />
                </el-select>
              </section>
            </el-col>
            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">游戏结果</div>
                <el-select v-model="search.answerResult" placeholder="请选择游戏结果搜索" style="width: 80%;">
                  <el-option
                      v-for="item in answerResultOptions"
                      :key="item.id"
                      :label="item.dictName"
                      :value="item.id"
                  />
                </el-select>
              </section>
            </el-col>
          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          &lt;!&ndash;          <span class="search-more" @click="searchshow = !searchshow">
                      精简筛选条件
                      <i class="el-icon-arrow-up"/>
                    </span>&ndash;&gt;
        </section>
      </section>
    </el-collapse-transition>-->
    <section class="main-buttons">
      <section class="main-buttons-title">
        <span v-if="type==='dh'">兑换明细</span>
        <span v-else>消费明细</span>
      </section>
      <section class="main-buttons-btns">
        <el-button v-if="type==='dh'" class="filter-item" style="margin-left: 10px;" @click="handleExport">导出</el-button>
        <el-button style="padding: 10px 30px;" @click="handleCancel()">返回</el-button>
      </section>
    </section>
    <section class="main-table">
      <v-table
        :list="list"
        :tag="tableTag"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :selection="false"
      />
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryRecordDetail, exportDetailFile, exportDetailMask, exportDetailNoMask } from '../api/index'
import permission from '@/directive/permission/index.js'
import { exportSign } from '@/utils/fileImportOrExportSign'
import CryptoJS from '@/utils/aesJiaJM'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
export default {
  name: 'IntegralExchangeRecordDetail',
  components: { Pagination, VTable },
  directives: { permission },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      searchshow: true,
      search: {
        isDraw: '',
        answerResult: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      id: '',
      userId: '',
      type: '',
      tableTag: 'integralExchangeRecordDetail'
    }
  },
  created() {
    this.id = this.$route.query.i
    this.userId = this.$route.query.userId
    this.type = this.$route.query.t
    if (this.type === 'xf') {
      this.tableTag = 'hfconfigOrderDetail'
    }
    this.getList()
  },
  methods: {
    handleExport() {
      let query = {
        userId: this.userId
      }
      let url = ''
      let fileName = ''
      if (this.type == 'dh') {
        query.activityId = this.id
        fileName = '兑换明细详情.xlsx'
        url = '/backend/exchangeActivity/activityStatisticsUserExport'
      } else {
        query.giveId = this.id
        fileName = '消费明细详情.xlsx'
        url = '/backend/jdActivity/jdOrderExport'
      }
      query = exportSign(query).obj
      if (this.type == 'dh') {
        const loading = this.$loading({
          lock: true,
          text: '请稍后',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.3)'
        })
        exportDetailFile(query, url).then((res) => {
          loading.close()
          const content = res.data
          const blob = new Blob([content])
          if ('download' in document.createElement('a')) {
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // 释放URL 对象
            document.body.removeChild(elink)
          } else {
            navigator.msSaveBlob(blob, fileName)
          }
        }).catch(() => {
          // this.$message.error()
          loading.close()
        })
      } else {
        exportCheck('WELFARE_PAYMENT_INTEGRALCONFIG', '', exportDetailMask, exportDetailNoMask, query, fileName)
      }
    },
    handleCancel() {
      this.$router.back()
    },

    filtercolumn(scope, item) {
      if (item === 'phoneNumber') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        userId: this.userId,
        activityId: this.id
      }
      let url = ''
      if (this.type == 'dh') {
        url = '/backend/exchangeActivity/getActivityStatisticsUser'
      } else {
        url = '/backend/huifuOrder/queryPage'
      }
      return new Promise((resolve, reject) => {
        queryRecordDetail(query, url).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }

  }
}
</script>
<style lang="scss">
@import '@/styles/mixin.scss';

.integral-exchange-record-detail {
  padding: 0 10px 10px;

  .box-card {
    margin: 10px;
  }

  .main-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            &.el-date-editor input {
              padding-left: 30px;
            }

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }
}
</style>
